//
//  TTStoneCollectionViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/8/21.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTStoneCollectionViewCell.h"

@interface TTStoneCollectionViewCell ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation TTStoneCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColorHex(F0F4F7);
        _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        _imageView.contentMode = UIViewContentModeCenter;
        [self addSubview:_imageView];
        
        _titleLabel = [UILabel labelTextCenterWithTitle:@"" color:UIColorHex(333333) fontSize:15];
        _titleLabel.frame = self.bounds;
        [self addSubview:_titleLabel];
        
        
    }
    return self;
}

- (void)setModel:(TTSearchStoneModel *)model
{
    _model = model;
    if (model.imageName.length > 0) {
        self.imageView.image = [UIImage imageNamed:model.imageName];
        self.titleLabel.hidden = YES;
        self.imageView.hidden = NO;
    } else {
        self.titleLabel.text = model.title;
        self.titleLabel.hidden = NO;
        self.imageView.hidden = YES;
    }
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    if (selected) {
        
        if (self.model.imageName.length > 0) {
            NSString *imgName = [NSString stringWithFormat:@"%@_sel", self.model.imageName];
            self.imageView.image = [UIImage imageNamed:imgName];
        }
        self.backgroundColor = kMainColor;
        self.titleLabel.textColor = [UIColor whiteColor];
    } else {
        
        if (self.model.imageName.length > 0) {
            self.imageView.image = [UIImage imageNamed:self.model.imageName];
        }
        
        self.backgroundColor = UIColorHex(F0F4F7);
        self.titleLabel.textColor = UIColorHex(333333);
    }
    
}


@end
